﻿using LiveCharts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using Zhaoxi.Industrial.Base;
using Zhaoxi.Industrial.Model;

namespace Zhaoxi.Industrial.ViewModel
{
    internal class SystemMonitorViewModel:NotifyPropertyBase
    {
        public ObservableCollection<LogModel> LogList { get; set; } = new ObservableCollection<LogModel>();

        private DeviceModel _CurrentDevice;

        public DeviceModel CurrentDevice
        {
            get { return _CurrentDevice; }
            set { 
                _CurrentDevice = value; 
                this.RaisePropertyChanged(); 
            }
        }

        private bool _IsShowDetail = false;

        public bool IsShowDetail
        {
            get { return _IsShowDetail; }
            set { 
                _IsShowDetail = value; 
                this.RaisePropertyChanged(); 
            }
        }



        public DeviceModel device { get; set; }

        public CommandBase ComponentCommand { get; set; }
        public SystemMonitorViewModel()
        {
            LogDataInit();
            DeviceListInit();

            this.ComponentCommand = new CommandBase(new Action<object>(DoTowerCommand));
        }

        public void LogDataInit() { 
            this.LogList.Add(new LogModel() { RowNumber = 1, DeviceName = "冷却塔1#", Message = "已启动", logType = LogType.info});
            this.LogList.Add(new LogModel() { RowNumber = 2, DeviceName = "冷却塔2#", Message = "已启动", logType = LogType.info });
            this.LogList.Add(new LogModel() { RowNumber = 3, DeviceName = "冷却塔3#", Message = "液位极地", logType = LogType.warning });
            this.LogList.Add(new LogModel() { RowNumber = 4, DeviceName = "循环水垒1#", Message = "频率过大", logType = LogType.warning });
            this.LogList.Add(new LogModel() { RowNumber = 5, DeviceName = "循环水垒2#", Message = "已停机", logType = LogType.info });
            this.LogList.Add(new LogModel() { RowNumber = 6, DeviceName = "循环水垒3#", Message = "已停机", logType = LogType.info });
        }

        public void DeviceListInit() {
            this.device = new DeviceModel();
            this.device.name = "冷却塔#1";
            this.device.isRunning = true;
            this.device.isWarning = true;
            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "1",
                value_name = "液位",
                unit = "m",
                content = 45,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new  LiveCharts.Defaults.ObservableValue(0),new LiveCharts.Defaults.ObservableValue(0)}
            });

            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "2",
                value_name = "出口压力",
                unit = "Mpa",
                content = 35,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0) }
                //初始化2个集合对象  LiveCharts.Defaults 是命名空间 2个集合的默认值都是0
            });

            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "3",
                value_name = "出口温度",
                unit = "℃",
                content = 15,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0) }
            });

            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "4",
                value_name = "补水压力",
                unit = "Mpa",
                content = 17,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0) }
            });

            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "5",
                value_name = "液位",
                unit = "m",
                content = 56,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0) }
            });

            this.device.monitorValues.Add(new MonitorValuesModel()
            {
                value_id = "6",
                value_name = "入口压力",
                unit = "Mpa",
                content = 5,
                Values = new ChartValues<LiveCharts.Defaults.ObservableValue> { new LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0) }
            });

            this.device.WarningList.Add(new WarningMessageModel { D_Message = "冷却塔1#液位极低，当前值：0" });
            this.device.WarningList.Add(new WarningMessageModel { D_Message = "冷却塔1#入口压力极低，当前值：0" });
            this.device.WarningList.Add(new WarningMessageModel { D_Message = "冷却塔1#入口温度极低，当前值：0" });

            
        }

        private void DoTowerCommand(Object obj) {
            CurrentDevice = obj as DeviceModel;
            this.IsShowDetail = true;
        }
    }
}
